package com.iplatform.iplatformuser.privilege.api;

import com.iplatform.iplatformuser.common.ConstantUtil;
import com.iplatform.iplatformuser.common.ResponseMsg;
import com.iplatform.module.privilege.TargetGroupBean;
import com.iplatform.iplatformuser.privilege.service.inter.targetGroupService;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Map;

/**
 *
 * @author zql
 *
 */
@Api(tags="指标分组")
@Controller
@RequestMapping("/api/v1/targetGroup")
public class ApiTargetGroupController {

	@Autowired
	private targetGroupService service;

	@ApiOperation("新增分组")
	@ApiImplicitParams({
		@ApiImplicitParam(dataType="String", paramType="query", name="groupName", value="分组名称", required=true),
		@ApiImplicitParam(dataType="String", paramType="query", name="remark", value="备注", required=false)
	})
	@ApiResponses({ @ApiResponse(code = HttpServletResponse.SC_OK, message = "成功"),
		@ApiResponse(code = HttpServletResponse.SC_CONFLICT, message = "没有做到API使用规范") })
	@RequestMapping(value="add", method= RequestMethod.POST)
	public ResponseEntity<ResponseMsg> addGroup(@ApiParam(hidden=true) @RequestParam Map<String, String> formMap){
		service.addGroup(formMap);
		return new ResponseEntity<>(new ResponseMsg(ConstantUtil.SUCCESS), HttpStatus.OK);
	}

	@ApiOperation("查询分组")
	@RequestMapping(value="queryGroup", method= RequestMethod.POST)
	public ResponseEntity<List<TargetGroupBean>> queryGroup(@ApiParam(hidden=true) @RequestParam Map<String, String> formMap){
		List<TargetGroupBean> resultList = service.queryGroup(formMap);
		return new ResponseEntity<>(resultList, HttpStatus.OK);
	}

	@ApiOperation("修改组名")
	@ApiImplicitParams({
		@ApiImplicitParam(dataType="String", paramType="query", name="id", value="分组id", required=true),
		@ApiImplicitParam(dataType="String", paramType="query", name="groupName", value="分组名称", required=true)
	})
	@RequestMapping(value="update", method= RequestMethod.POST)
	public ResponseEntity<ResponseMsg> updateGroup(@ApiParam(hidden=true) @RequestParam Map<String, String> formMap){
		service.updateGroup(formMap);
		return new ResponseEntity<>(new ResponseMsg(ConstantUtil.SUCCESS), HttpStatus.OK);
	}

	@ApiOperation("删除分组")
	@ApiImplicitParams({
		@ApiImplicitParam(dataType="String", paramType="query", name="id", value="分组id", required=true),
	})
	@RequestMapping(value="delete", method= RequestMethod.POST)
	public ResponseEntity<ResponseMsg> deleteGroup(@ApiParam(hidden=true) @RequestParam Map<String, String> formMap){
		service.deleteGroup(formMap);
		return new ResponseEntity<>(new ResponseMsg(ConstantUtil.SUCCESS), HttpStatus.OK);
	}
}
